//
//  YDHomeMarketCollectionCell.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/23.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDHomeMarketCollectionCell.h"
#import "YDHomeMarketModel.h"



@interface YDHomeMarketCollectionCell()


//指数类型
@property (nonatomic , weak) UILabel *exponentialType;
//点数
@property (nonatomic , weak) UILabel *point;
//涨跌幅度
@property (nonatomic , weak) UILabel *upsandDowns;
//涨跌百分比
@property (nonatomic , weak) UILabel *percentage;

//三角图片
@property (nonatomic , weak) UIImageView *accView;


@end


@implementation YDHomeMarketCollectionCell


-(void)setModel:(YDHomeMarketModel *)model
{
    _model = model;
    
    //指数类型
    self.exponentialType.text = model.name;
    
    
    self.percentage.text = model.upDownRate;
    
    self.upsandDowns.text = [NSString stringWithFormat:@"%.2f",[model.upDropPrice floatValue]];
    //stockMarket-down  stockMarket-up
    if (model.upOrDown) {//涨NumberColor(222, 95, 65);
        self.point.textColor = NumberColor(222, 95, 65);
        self.percentage.textColor = NumberColor(222, 95, 65);
        self.upsandDowns.textColor = NumberColor(222, 95, 65);
        
        self.point.text = [NSString stringWithFormat:@"%.2f",model.lastPrice.floatValue];
        self.accView.image = [UIImage imageNamed:@"stockMarket-up"];
    }else{//跌NumberColor(70, 192, 50);
        self.point.textColor =  NumberColor(70, 192, 50);
        self.percentage.textColor = NumberColor(70, 192, 50);
        self.upsandDowns.textColor = NumberColor(70, 192, 50);
        
        self.point.text = [NSString stringWithFormat:@"%.2f",model.lastPrice.floatValue];
        self.accView.image = [UIImage imageNamed:@"stockMarket-down"];
    }
    
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self exponentialType];
        [self point];
        [self upsandDowns];
        [self percentage];
        [self accView];
        //去掉分割线
        //[self lineView];
        
    }
    return self;
}
-(UILabel *)exponentialType
{
    if (_exponentialType == nil) {
        UILabel *exponentialType = [[UILabel alloc] init];
        [self.contentView addSubview:exponentialType];
        exponentialType.textColor = NumberColor(129, 128, 129);
        exponentialType.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        exponentialType.textAlignment = NSTextAlignmentCenter;
        exponentialType.backgroundColor = [UIColor clearColor];
        exponentialType.text = @"上证指数";
        exponentialType.adjustsFontSizeToFitWidth = YES;
        [exponentialType mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.equalTo(@(rate375(53)));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(13));
            }else{
                make.top.equalTo(self).offset(rate750(13));
            }
        }];
        exponentialType.adjustsFontSizeToFitWidth = YES;
        _exponentialType = exponentialType;
    }
    return _exponentialType;
}

-(UILabel *)point
{
    if (_point == nil) {
        UILabel *point = [[UILabel alloc] init];
        [self.contentView addSubview:point];
        point.textColor = NumberColor(222, 95, 65);
        point.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        point.textAlignment = NSTextAlignmentLeft;
        point.backgroundColor = [UIColor clearColor];
        point.text = @"3293.09";
        point.adjustsFontSizeToFitWidth = YES;
        point.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
        [point mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.centerY.equalTo(self);
            make.left.equalTo(self.exponentialType.mas_left).offset(-rate375(5));
        }];
        point.adjustsFontSizeToFitWidth = YES;
        _point = point;
    }
    return _point;
}

-(UILabel *)upsandDowns
{
    if (_upsandDowns == nil) {
        UILabel *upsandDowns = [[UILabel alloc] init];
        [self.contentView addSubview:upsandDowns];
        upsandDowns.textColor = NumberColor(70, 192, 50);
        upsandDowns.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        upsandDowns.textAlignment = NSTextAlignmentRight;
        upsandDowns.backgroundColor = [UIColor clearColor];
        upsandDowns.text = @"-9.01";
        upsandDowns.adjustsFontSizeToFitWidth = YES;
        [upsandDowns mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.top.equalTo(self.point.mas_bottom).offset(5);
            make.right.equalTo(self.mas_centerX).offset(-5);
        }];
        upsandDowns.adjustsFontSizeToFitWidth = YES;
        _upsandDowns = upsandDowns;
    }
    return _upsandDowns;
}
-(UILabel *)percentage
{
    if (_percentage == nil) {
        UILabel *percentage = [[UILabel alloc] init];
        [self.contentView addSubview:percentage];
        percentage.textColor = NumberColor(70, 192, 50);
        percentage.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        percentage.textAlignment = NSTextAlignmentLeft;
        percentage.backgroundColor = [UIColor clearColor];
        percentage.text = @"-0.29%";
        percentage.adjustsFontSizeToFitWidth = YES;
        [percentage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.top.equalTo(self.point.mas_bottom).offset(5);
            make.left.equalTo(self.mas_centerX).offset(5);
        }];
        percentage.adjustsFontSizeToFitWidth = YES;
        _percentage = percentage;
    }
    return _percentage;
}
-(UIImageView *)accView
{
    if (_accView == nil) {
        UIImageView *accView = [[UIImageView alloc] init];
        [self.contentView addSubview:accView];
        accView.backgroundColor = [UIColor clearColor];
        [accView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.point.mas_left).offset(-rate375(3));
            make.centerY.equalTo(self.point);
        }];
        _accView = accView;
    }
    return _accView;
}
-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(self).multipliedBy(0.64);
            make.right.equalTo(self);
            make.width.equalTo(@0.5);
            make.centerY.equalTo(self);
        }];
        _lineView = lineView;
    }
    return _lineView;
}






@end
